//
//  BGJoyousViewControll.m
//  bingke
//
//  Created by zhangkt zhangkt on 12-10-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BGJoyousViewControll.h"

@implementation BGJoyousViewControll

@synthesize isOrHide;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"BGMenuView" owner:nil options:nil];
    UIView *myView = [array objectAtIndex:0];
    myView.frame = [BGMenuView getHideFrame];
    [self.view addSubview:myView];
    myView.backgroundColor = [UIColor clearColor];
    
    upView = [[BGHeadView alloc]init];
    NSArray *headViewArray = [[NSBundle mainBundle] loadNibNamed:@"BGHeadView" owner:nil options:nil];
    upView = [headViewArray objectAtIndex:0];
    upView.frame = CGRectMake(0, 0, 320, 83);
    [self.view addSubview:upView];
    upView.backgroundColor = [UIColor clearColor];
    
    isOrHide = YES;
    
    upView.delegate =self;
    
    actionSheet = [[BGActionSheet alloc] init];
    detailView = [[BGDetailView alloc] init];
    
    NSArray *mArray = [[NSBundle mainBundle] loadNibNamed:@"BGDetailView" owner:nil options:nil];
    detailView = [mArray objectAtIndex:0];
    detailView.frame = [BGDetailView getHideFrame];
    detailView.backgroundColor = [UIColor grayColor];
    detailView.alpha = 0.8;
    [self.view addSubview:detailView];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

-(void) sharedview
{
    if(isOrHide ==YES)
    {
        NSArray *mArray = [[NSBundle mainBundle] loadNibNamed:@"BGActionSheet" owner:self options:nil];
        actionSheet = [mArray objectAtIndex:0];
        actionSheet.delegate = self;
        actionSheet.informationText.delegate = self;
        actionSheet.frame = CGRectMake(0, 460, 320, 180);
        [UIView animateWithDuration:0.5 animations:^() 
        {
            actionSheet.frame = CGRectMake(0, 280, 320, 180);
            actionSheet.backgroundColor = [UIColor clearColor];
            [self.view addSubview:actionSheet];
        } completion:^(BOOL finished) 
        {
            //[self addPicEvent]; 
        }];
        isOrHide = !isOrHide;
    }
    else
    {
        actionSheet.frame = CGRectMake(0, 280, 320, 180);
        [UIView animateWithDuration:0.5 animations:^() 
        {
            actionSheet.frame = CGRectMake(0, 460, 320, 180);
        }];
        isOrHide = !isOrHide;
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void) changeBool
{
    isOrHide = !isOrHide;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)searchDetails:(id)sender 
{
    NSLog(@"***************");
   
    UIButton *button = (UIButton *)sender;
    
    [UIView beginAnimations:@"present-countdown" context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(hideMenuAnimationStop)];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    
    if(isOrHide)
    {
        detailView.frame = [BGDetailView getFrame];
        button.frame = CGRectMake(254, 241, 44, 43);
    }
    else
    {
        detailView.frame = [BGDetailView getHideFrame];
        button.frame = CGRectMake(254, 426, 44, 43);
    }
    isOrHide = !isOrHide;
    [UIView commitAnimations];    
}

@end
